package com.lance.answer.gui.answer.gk.answer.lms;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.google.common.collect.Maps;
import com.lance.answer.gui.answer.Util;
import com.lance.answer.util.HttpUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;
import java.util.List;
import java.util.Map;

/**
 * <p>保存所有的视频信息<p>
 * <p>
 * <p>
 * <p>
 * <p>
 * 工程经济,size:1
 *
 * @author : fengx
 * @since JDK8.0
 * create by fengx on 2021/7/15 14:47
 */
public class YiWangYiSaveVideoInfo {




    // static void watchVideo(WebDriver driver,String urlTask)throws Exception{


    public static void main(String[] args) throws Exception {
        String driverPath = "d:\\ynouAutoStudy\\chromedriver.exe";
        ChromeDriver driver = Util.getDriver(driverPath);
        String url = "https://menhu.pt.ouchn.cn/site/ouchnPc/index";
        driver.get(url);
        Thread.sleep(3000);



        String userName = "1942001212871";
        String pwd = "Ouchn@2021";
        String subjectName = "习近平新时代中国特色社会主义思想";

        WebElement userNameInput = driver.findElement(By.id("loginName"));
        userNameInput.clear();
        userNameInput.sendKeys(userName);
        //TimeUnit.SECONDS.sleep(1);

        WebElement passwordInput = driver.findElement(By.id("password"));
        passwordInput.clear();
        passwordInput.sendKeys(pwd);
        //TimeUnit.SECONDS.sleep(1);

        // FIXME 要输入验证码
        Thread.sleep(10000);

        //webDriverWait.until(ExpectedConditions.elementToBeClickable(By.id("loginId"))).sendKeys(username);

        WebElement loginBtn = driver.findElement(By.name("button"));

        loginBtn.click();

        Thread.sleep(10000);


        // 在题库里获取答案

        String courseId = "14182";

        String courseUrl = "https://lms.ouchn.cn/course/"+courseId+"/ng#/";
        driver.get(courseUrl);



        String getUrl = "https://lms.ouchn.cn/api/course/14182/activity-reads-for-user";

        String cookie = Util.getCookie(driver.manage().getCookies());



        Map<String,String> heads = Maps.newHashMap();
        heads.put("referer","https://lms.ouchn.cn/course/"+courseId+"/ng");
        heads.put(":method","GET");
        heads.put(":authority","lms.ouchn.cn");
    //    heads.put("origin","https://lms.ouchn.cn");
        heads.put("cookie",cookie);
        heads.put(":path","/api/course/"+courseId+"/activity-reads-for-user");
        heads.put("accept","application/json, text/plain, */*");

        String  result= HttpUtil.getLmsOuchn(getUrl,cookie,heads);
        System.err.println("result:"+result);






        Thread.sleep(200000000);





//
    }








}
